from elasticsearch import Elasticsearch
import os
import time

# 使用elasticsearch库创建Elasticsearch客户端实例
# es = Elasticsearch([{'host': '192.168.80.35', 'port': 9200, 'scheme': 'https'}])

es = Elasticsearch(["https://192.168.80.35:9200"], http_auth=('elastic', '123456'), verify_certs=False)


# es = Elasticsearch("http://127.0.0.1:9200", basic_auth=('elastic', '8ecP5-m+U7Ru-qDp_*C9'))

def es_index_del():
    index_names = es.cat.indices(format="json")
    for index in index_names:
        indexId = index['index']
        print(indexId)

        if indexId.startswith("t-", 0):
            print(indexId)
            es.indices.delete(index=index['index'])
        if indexId.startswith("tj", 0):
            print(indexId)
            es.indices.delete(index=index['index'])
        if indexId.startswith("z-", 0):
            print(indexId)
            es.indices.delete(index=index['index'])

        # es.indices.delete(index=index['index'])

es_index_del()
